package demo;

import java.util.Scanner;
import java.util.spi.AbstractResourceBundleProvider;

public class lian {
    public static void main(String[] args) {
        /*
        评委打分  ： n人  最后输出平均分
            平均分去掉最高和最低 之后的n-2位评委
            使用方法实现
         */
        Scanner scan=new Scanner(System.in);
        System.out.println("欢迎来到主持人大赛！");
        System.out.println("要求为每位主持人打分，得分高的获胜");
        int num= RenShu();
        double[] score=new double[num];
        for (int i=0;i<num;i++) {
            System.out.println("请输入第" + (i+1) + "位评委的得分：");
            score[i] =Score();
        }
        double result=Result(score);
        System.out.println("总的得分结果："+result);
        double result2=Re(num,score,result);
        System.out.println("该主持人的最终得分为："+result2);



    }
    public static int RenShu() {
        Scanner scan=new Scanner(System.in);
        int num1;
        while (true) {
            System.out.println("请输入评委人数: ");
            num1 = scan.nextInt();
            if (num1<=2){
                System.out.println("评委人数需要大于2人!");
            }else {
                break;
            }
        }
        return num1;
    }
    public static double Score(){
        Scanner scan=new Scanner(System.in);

        while (true) {
            double sc= scan.nextDouble();
            if (sc<0||sc>100){
                System.out.println("请重新输入合理范围(0~100)的分数：");
            }else {
                return sc;
            }
        }

    }
    public static double Result(double[] sco){
        double max=sco[0];
        double min=sco[0];
        double sum=0;
        for (int num2 = 0; num2 < sco.length; num2++) {
            sum+=sco[num2];
        }
        for (int num = 0; num < sco.length; num++) {
            if (max<sco[num]){
                max=sco[num];
            }
        }
        for (int num1 = 0; num1 < sco.length; num1++) {
            if (min>sco[num1]){
                min=sco[num1];
            }
        }
        double result=sum-max-min;
        return result;
    }
    public static double Re(int num,double[] sc,double sum1){

        sum1=Result(sc);
        double result=sum1/(num-2);
        return result;
    }
}